package com.u.iot.sleep.service;

import com.alibaba.fastjson.JSON;
import com.u.iot.sleep.model.UserSleepStatus;
import jakarta.annotation.Resource;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

import java.util.Random;
import java.util.UUID;

/**
 * @program: u-InternetOfThings
 * @description: 睡眠服务类业务逻辑层
 * @author: Alex Wu
 * @createDate: 2025-03-21 14:31
 **/

@Service
public class SleepService {


    @Resource
    private KafkaTemplate<String, String> kafkaTemplate;

    // 发送消息
    public void sendMessage() {
        Random random = new Random();
        Long userId = 1L;
        String status = "sleep";
        Long eventTime = System.currentTimeMillis() - random.nextInt(5) * 1000;
        Integer breathingRate =  random.nextInt(100) ;
        Integer heartRate =  random.nextInt(100) ;
        Integer turnsNum =  random.nextInt(100) ;
        UserSleepStatus userSleepStatus = new UserSleepStatus(userId, status, eventTime, breathingRate, heartRate, turnsNum);
        String msg = JSON.toJSONString(userSleepStatus);
        kafkaTemplate.send("test", msg);
        System.out.println("Message sent: " + msg);
    }

}
